package com.example.smartcity1.news;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.smartcity1.R;
import com.example.smartcity1.bean.NewsBean;
import com.google.gson.Gson;

import static com.example.smartcity1.network.RetrofitClient.IP;

public class NewsPageActivity extends AppCompatActivity {

    private TextView titleView;
    private ImageView imgView;
    private TextView contentView;
    private LinearLayout linearLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_news_page);
        ActionBar supportActionBar = getSupportActionBar();
        supportActionBar.setDisplayHomeAsUpEnabled(true);
        initView();
        Intent intent = getIntent();
        String news = intent.getStringExtra("news");
        Gson gson = new Gson();
        NewsBean.RowsDTO data = gson.fromJson(news,NewsBean.RowsDTO.class);
        supportActionBar.setTitle(data.getTitle());
        titleView.setText(data.getTitle());
        Glide.with(this).load(IP + data.getImgUrl())
                .placeholder(R.drawable.ic_baseline_cloud_download_24)
                .centerCrop()
                .into(imgView);
        contentView.setText(data.getContent());
        linearLayout.setOnClickListener(v -> {
            Intent intent1 = new Intent(this,NewsCommentsActivity.class);
            intent1.putExtra("id",data.getId());
            startActivity(intent1);
        });
    }

    private void initView() {
        titleView = findViewById(R.id.news_page_title);
        imgView = findViewById(R.id.news_page_img);
        contentView = findViewById(R.id.news_page_content);
        linearLayout = findViewById(R.id.linearLayout);
    }

    @Override
    public boolean onSupportNavigateUp() {
        finish();
        return super.onSupportNavigateUp();
    }
}